<?php
include('config.php');

$where = "1";

$guest_id = isset($_GET['id']) ? $_GET['id'] : '';
$rs = $mysql->selectList('guest',"guest_id='{$guest_id}'");
$guest_name = $rs[0]['guest_name'];
if($guest_name){
	$where .= " and guest_name = '{$guest_name}'";
}

$sql = "SELECT buy.*,n.number_name,b.breed_name,t.type_name,g.guest_name FROM buy_goods_log buy left join `number` n on buy.number_id=n.number_id left join breed b on buy.breed_id=b.breed_id left join type t on buy.type_id=t.type_id left join guest g on buy.guest_id=g.guest_id";
$sql .= " WHERE ".$where." ORDER BY buy.buy_goods_id DESC LIMIT 10";
$n = 0;
echo "<table id='tables'>";
echo "<tr class='query_top_tr'>";
echo "<th>类别</th><th>品种</th><th>编号</th><th>数量</th><th>售出单价</th><th>售出总价</th><th>售出日期</th><th>客户</th>";
$rs = $mysql->execute($sql);
while($row = mysql_fetch_assoc($rs)){
	$n = $n;
	$num = $n%2;
	$total_price = $row['buy_goods_num'] * $row['buy_goods_price'];
	echo "<tr class='query_tr{$num}'><td>{$row['type_name']}</td><td>{$row['breed_name']}</td><td>{$row['number_name']}</td><td>{$row['buy_goods_num']}</td><td>{$row['buy_goods_price']}</td><td>{$total_price}</td><td>{$row['buy_goods_date']}</td><td>{$row['guest_name']}</td></tr>";
	$n++;
}
echo "</tr>";
echo "</table>";